package avicit.bdp.dds.api.service;

import avicit.bdp.common.base.BaseService;
import avicit.bdp.common.service.dto.BdpColumnDTO;
import avicit.bdp.common.service.dto.BdpTableDTO;
import avicit.bdp.common.utils.EntityUtils;
import avicit.bdp.dds.dao.entity.LineageTableDTO;
import avicit.bdp.dds.dao.mapper.LineageTableDAO;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/** 
 * 数据血缘表关系服务
 *
 */
@Service
@Transactional
public class LineageTableService extends BaseService<LineageTableDAO, LineageTableDTO> {

    @Autowired
    private LineageTableDAO lineageTableDAO;

    public int batchInsert(List<LineageTableDTO> lineageTableList) {
        if (CollectionUtils.isNotEmpty(lineageTableList)) {
            for (LineageTableDTO obj : lineageTableList) {
                EntityUtils.setCreateAndUpdateInfo(obj);
            }
            return lineageTableDAO.batchInsert(lineageTableList);
        }
        return 0;
    }

    public List<LineageTableDTO> getAllLineageTable(){
        return lineageTableDAO.getAllLineageTable();
    }

    public BdpTableDTO selectTableById(String tableId){
        return lineageTableDAO.selectTableById(tableId);
    }

    public List<BdpColumnDTO> selectAllColumnByTableIds(List<String> tableIdList) {
        return lineageTableDAO.selectAllColumnByTableIds(tableIdList);
    }

}
